﻿<!DOCTYPE>

<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
    <title>临时物料提请-发起</title>
    <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
    <style type="text/css">
        .linkbutton{margin-left:20px;width:85px;}
        table tr td{padding:0px 5px}
    </style>
</head>
<body>
      <div class="panelSection">    
        <div class="easyui-panel " title="查询区域" style="padding:3px;width:100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false"> 
           <form id="searchForm" method="post">
	    	<table>
	    		<tr class="divLabel">
	    			<td>发动机号:</td>
                    <td>生产订单号:</td>
                    <td>订单类型:</td>
	    		</tr>
	    		<tr>
	    			<td><input class="easyui-textbox" type="text" name="Machine" style="width: 120px; height: 22px"/></td>
                    <td><input class="easyui-textbox" type="text" name="mfgOrderName" style="width: 120px; height: 22px"/></td>
	    			<td><input id="ORDERTYPE" name="OrderTypeIndex" style="width: 120px; height: 22px"/></td>
                    <td><a href="javascript:void(0)" class="easyui-linkbutton linkbutton" onclick="page.searchData()">查询</a></td>
	    			<td><a href="javascript:void(0)" class="easyui-linkbutton linkbutton" onclick="page.searchReset()">重置</a></td>
                    <td></td>
	    		</tr>
	    	</table>
	    </form> 
        </div>
      </div>
      <div class="panelSection">    
        <div class="easyui-panel " title="订单列表" style="padding:3px;width:100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false"> 
            <table id="LaunchTable" style="height:230px;width:100%"></table>
             <div id="pp" style="float: right" class="easyui-pagination" data-options="   
                 layout:['first','prev','next','last','manual','info'],              
                    total: 0,
                    showPageList: false,
                    showPageInfo: false,
                    showRefresh: false,
                    afterPageText:'共&nbsp{pages}&nbsp页',
                     buttons:[{
                            iconCls:'',
                            text:'Go',
                            id:'pageGo'
                    }]
                ">
                    </div>
        </div>
      </div>
      <div class="panelSection" id="EditorpanelSection">    
        <div class="easyui-panel " title="编辑区域" style="padding:3px;width:100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false"> 
            <form id="EditorForm">
                  <table class="tabel" cellpadding="5">
	    		    <tr class="divLabel">
	    			    <td>生产订单号</td>
                        <td>领用类型</td>
                        <td>物料</td>
                        <td>申请数量</td>
                        <td>领料原因</td>
                        <td></td>
	    		    </tr>
	    		    <tr>
	    			    <td><input id="mfgOrderID" type="hidden"/><input class="easyui-textbox" type="text" name="mfgOrderName" style="width: 150px; height: 22px" id="mfgOrderName" /></td>
	    			    <td><input class="easyui-textbox" type="text" name="TMRType" style="width: 150px; height: 22px" id="TMRType" /></td>
                        <td><input id="ProductID" type="hidden"/><input id="DESCRIPTION" type="hidden"/><input id="PRODUCTNAME" type="hidden"/><div class="ProductCombox"></div></td>
                        <td><input class="easyui-numberbox" type="text" name="ApplyNum" style="width: 150px; height: 22px" id="ApplyNum" /></td>
                        <td><input class="easyui-textbox" type="text" name="TMRReason" style="width: 250px; height: 22px" id="TMRReason" /></td>
                        <td> <a href="javascript:void(0)" class="easyui-linkbutton linkbutton" onclick="page.AppendRow()">新增行 +</a>
                            <a href="javascript:void(0)" class="easyui-linkbutton linkbutton" onclick="page.DeleteRow()">删除行 —</a></td>
	    		    </tr>
	    	    </table>
              </form>
              <div>
                <div style="width:880px;float:left"><table id="TempMaterialRequestDetailTable" style="height:200px;width:100%"></table></div>
              </div>
      </div>
      </div>
      <div class="panelSection">    
        <div class="easyui-panel " title="临时领料提请" style="padding:3px;width:100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false"> 
           <table id="TempMaterialRequestTable" style="height:200px;width:100%"></table>
        </div>
      </div>
      <div class="panelSection">    
        <div class="easyui-panel " title="按钮区域" style="padding:3px;width:100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false"> 
            <div style="margin:15px 0px">
              <a href="javascript:void(0)" class="easyui-linkbutton linkbutton" onclick="page.saveTempMaterialRequestData()">保存</a>
              <a href="javascript:void(0)" class="easyui-linkbutton linkbutton" onclick="page.submitTempMaterialRequestData()">提交</a>
              <a href="javascript:void(0)" class="easyui-linkbutton linkbutton" onclick="page.deleteTempMaterialRequestData()">删除</a>
            </div>
      </div>
      </div>
      <div id="statusMessage" style="font-size: 14px; height: 40px"></div>
     
</body>
</html>

<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/json2.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script type="">
/*
创建人：longb
日期：2023-03-02
描述：临时领料提请-发起js
*/
var page = {
    pagetotal: 0,
    pageSize: 20,
    pageNumber: 1,
    editIndex:undefined,
    rootPath: getRootPath(), //网站根路径
    ajaxUrl: getRootPath() + "/Ashx/ZsHandler/ZSTempMaterialRequestHandler.ashx",
    comboxUrl:getRootPath() + "/Ashx/ZsHandler/ZSSendRequestHandler.ashx",//combox下拉-调用后台的URL
    comboxAction:"GetAllProduct",//combox下拉-调用后台的具体方法
    //初始化页面
    init: function () {
        page.bind();
        customizedEasyuiPagination('pp'); //定制化分页
    },
    endEditing: function (gridId) {
        if (page.editIndex == undefined) { return true }
        if ($('#' + gridId).datagrid('validateRow', page.editIndex)) {
            $('#' + gridId).datagrid('endEdit', page.editIndex);
            page.editIndex = undefined;
            return true;
        } else {
            return false;
        }
    },
    //页面事件绑定
    bind: function () {
        $('#ORDERTYPE').combobox({
            data:[{id:0,text:'常规生产订单'},{id:1,text:'无物料号生产订单'}],
            valueField:'id',
            textField:'text',
            value:0
        });
        $('#TMRType').combobox({
            data:[{id:0,text:'SCLL|计划外领料'},{id:1,text:'BFFL|补废领料'}],
            valueField:'id',
            textField:'text',
            value:0
        });
        
        
        //订单列表
        $("#LaunchTable").datagrid({
            rownumbers: true,
            checkOnSelect: false,
            selectOnCheck: false,
            singleSelect: true,
            onLoadSuccess: function (data) {
                $('#pp').pagination('refresh', {// 改变选项，并刷新分页栏信息
                    total: page.pagetotal,
                    pageSize: page.pageSize,
                    pageNumber: page.pageNumber
                });
                customizedEasyuiPagination('pp'); //定制化分页
            },
           
            columns: [[
                 //{ field: 'MFGORDERID', width: 120, checkbox: true },
                 { field: 'MACHINENO', title: '发动机号', width: 120},
                 { field: 'MFGORDERNAME', title: '生产订单号', width: 150 },
                 { field: 'ORDERTYPENAME', title: '订单类型', width: 120 },
		         { field: 'MFGYPE', title: '订单类别', width: 130 }, //--
                 { field: 'PRODUCTNAME', title: '件号', width: 100 },
                 { field: 'PRODUCTDESCRIPTION', title: '件号名称', width: 120, },
                 { field: 'PRODUCTFAMILYNAME', title: '机型', width: 80 },
                 { field: 'FACTORYSTARDATE', title: '计划开始时间', width: 100 },
                 { field: 'FACTORYCOMPLETIONDATE', title: '计划结束时间', width: 100, }
	           ]],
            onSelect: function (index, row) {
              $('#mfgOrderName').textbox('setValue',row.MFGORDERNAME);
                $('#mfgOrderID').val(row.MFGORDERID);
                page.getTempMaterialRequestData();
            }
        });
      
       $('#TempMaterialRequestDetailTable').datagrid({
            singleSelect: true,
            //data:ReturnDetail,
            columns: [[
                 { field: 'PRODUCTID',hidden:true },
                 { field: 'PRODUCTNAME', title: '物料编码', width: 170},
                 { field: 'DESCRIPTION', title: '物料名称', width: 150 },
		         { field: 'ApplyNum', title: '申请数量', width: 130,editor:{type:'numberbox'} }, 
                 { field: 'TMRReason', title: '领料原因', width: 300,editor:{type:'textbox'} }
	           ]],
            onClickRow:function(index){
                if (page.editIndex != index){
				    if (page.endEditing('TempMaterialRequestDetailTable')){
					    $('#TempMaterialRequestDetailTable').datagrid('selectRow', index).datagrid('beginEdit', index);
					    page.editIndex = index;
				    } else {
					    $('#TempMaterialRequestDetailTable').datagrid('selectRow', page.editIndex);
				    }
			    }
            }
        });
        $('.ProductCombox').selectCombox({
            search: function () { },
            cancel: function () {  $('#ProductID').val('');$('#DESCRIPTION').val('');$('#PRODUCTNAME').val('');},
            selected: function (val, text,record){
                $('#ProductID').val(val);
                $('#DESCRIPTION').val(record.DESCRIPTION);
                $('#PRODUCTNAME').val(record.PRODUCTNAME);
                $('#txtCombox').textbox('setValue',text);
                $('#divComboxTxt').show();
                $('#divComboxSelect').hide();
                $('#divComboxSearch').show();
                $('#divComboxClear').hide();
            }
        });

        $('#TempMaterialRequestTable').datagrid({
            rownumbers: true,
            nowrap:false,
            columns: [[
                 { field: 'ZSTEMPMATERIALREQUESTID', width: 120, checkbox: true },
                 { field: 'ZSTEMPMATERIALREQUESTNO', title: '申请单号', width: 170},
                 { field: 'TMRTYPE', title: '领用类型', width: 100,formatter:function(value,row,index){if(value=="0"){return'SCLL|计划外领料';}else{return'BFFL|补废领料';}}},
                 { field: 'MFGORDERNAME', title: '生产订单号', width: 120},
                 { field: 'PRODUCTNAME', title: '物料编码', width: 100},
                 { field: 'PRODUCTDESCRIPTION', title: '物料名称', width: 100 },
		         { field: 'APPLYNUM', title: '申请数量', width: 80 }, //--
                 { field: 'TMRREASON', title: '领料原因', width: 200 },
                 { field: 'STATUS', title: '状态', width: 100,formatter:function(value,row,index){if(value==2){return"已完成";}else if(value==1){return"待确认";}else{return"待提交";}} },
                 { field: 'CREATEDATENAME', title: '创建人', width: 100 },
                 { field: 'CREATEDATE', title: '创建时间', width: 150 },
                 { field: 'SUBMITNAME', title: '提交人', width: 100 },
                 { field: 'SUBMITDATE', title: '提交时间', width: 150 },
                 { field: 'CONFIRMNAME', title: '确认人', width: 100 },
                 { field: 'CONFIRMDATE', title: '确认时间', width: 150 }
	           ]],
        });
        //分页事件
        $('#pp').pagination({
            onSelectPage: function (pageNumber, pageSize) {
                page.pageSize = pageSize; page.pageNumber = pageNumber;
                page.GetOrderList();
            }
        });
        //绑定分页go按钮
        $('#pageGo').on("click", function () {
            var pageNumber = $(this).parents('tr').find('.pagination-num').val();
            page.pageNumber = pageNumber;
            page.GetOrderList();
        });
        //清除按钮
        $('#btnReset').on("click", function () {
            page.reset(true, true);
            page.pageNumber = 1; page.pagetotal = 0
            $('#pp').pagination('refresh', {
                total: page.pagetotal,
                pageSize: page.pageSize,
                pageNumber: page.pageNumber
            });
        });
    },
   
    //查询
    searchData: function () {
        page.reset(false, true);
        page.pageNumber = 1;
        page.GetOrderList();
    },
    //查询订单列表信息
    GetOrderList: function () {
        var frdata = $('#searchForm').serializeArray();
        var data = { };
        $.each(frdata, function () {
            data[this.name] = this.value
        });
        var param = {
            action: "GetOrderList",
            pageSize: page.pageSize,
            pageNumber: page.pageNumber,
            data: JSON.stringify(data),
            url:getRootPath() + "/Ashx/ZsHandler/ZSStockReturnApplyBillHandler.ashx"
        };
        page.post(param, function (res) {
            if (res.Result) {
                //console.info(res);
                page.pagetotal = res.RowCount;
                $('#LaunchTable').datagrid('loadData', res.DBTable);
            }
        });
    },
    AppendRow:function(){
        if (page.endEditing('TempMaterialRequestDetailTable')){
                page.reset();
                var insertRow={ProductID:$('#ProductID').val(),PRODUCTNAME:$('#PRODUCTNAME').val(),DESCRIPTION:$('#DESCRIPTION').val(),ApplyNum:$('#ApplyNum').numberbox('getValue'),TMRReason:$('#TMRReason').textbox('getValue')};
                var index=undefined;
                var rows=$('#TempMaterialRequestDetailTable').datagrid('getRows');
                if(insertRow.ProductID==""){displayMessage('请选择物料信息，再进行操作',false);return;}
                if(insertRow.ApplyNum==""){displayMessage('请输入申请数量，再进行操作',false);return;}
                if(insertRow.TMRReason==""){displayMessage('请输入领料原因，再进行操作',false);return;}
                $.each(rows,function(i,item){
                    if(item.ProductID==insertRow.ProductID){
                        index=i;
                        $('#TempMaterialRequestDetailTable').datagrid('updateRow',{index:index,row:insertRow});
                        $('#TempMaterialRequestDetailTable').datagrid('selectRow', index).datagrid('beginEdit', index);
                    }
                });
                if(index==undefined){
				    $('#TempMaterialRequestDetailTable').datagrid('appendRow',insertRow);
				    page.editIndex = $('#TempMaterialRequestDetailTable').datagrid('getRows').length-1;
				    $('#TempMaterialRequestDetailTable').datagrid('selectRow', page.editIndex).datagrid('beginEdit', page.editIndex);
                }
	        }
    },
    DeleteRow:function(){
        if (page.editIndex == undefined){return}
			$('#TempMaterialRequestDetailTable').datagrid('cancelEdit', page.editIndex).datagrid('deleteRow', page.editIndex);
			page.editIndex = undefined;
    },
    //保存领料提请单信息
    saveTempMaterialRequestData: function () {
        $('#TempMaterialRequestDetailTable').datagrid('acceptChanges');
        var rows=$('#TempMaterialRequestDetailTable').datagrid('getRows');
         if(rows.length==0){displayMessage("请选择至少录入一条领料提请单信息，再进行操作",false);return;}
        var param = {
            action: "saveTempMaterialRequestData",
            TMRType:$('#TMRType').combobox('getValue'),
            mfgOrderID:$('#mfgOrderID').val(),
            data: JSON.stringify(rows)
        };
        page.post(param, function (res) {
            if (res.Result) {
                page.getTempMaterialRequestData();
                $('#TempMaterialRequestDetailTable').datagrid('loadData',[]);
            }else{
                page.editIndex = undefined;
            }
            displayMessage(res.Message, res.Result);
        });
    },
    ///获取领料提请单数据
    getTempMaterialRequestData:function(){
       page.post({action:'getTempMaterialRequestData',mfgOrderID:$('#mfgOrderID').val()}, function (res) {
          $('#TempMaterialRequestTable').datagrid('loadData',res)
        });
    },
    ///提交领料提请单数据
    submitTempMaterialRequestData:function(){
        var rows=$('#TempMaterialRequestTable').datagrid('getChecked');
        var data=[];
        $.each(rows,function(index,item){
            if(item.STATUS==0){
                data.push(item);
            }
        });
        if(data.length==0){displayMessage("请选择至少一条【待提交】领料提请单信息，再进行操作",false);return;}
         page.post({action:'updateTempMaterialRequestData',data:JSON.stringify(data),type:'submit'}, function (res) {
            if (res.Result) {
                page.getTempMaterialRequestData();
            }
            displayMessage(res.Message, res.Result);
        });
    },
    ///删除领料提请单数据
    deleteTempMaterialRequestData:function(){
          var rows=$('#TempMaterialRequestTable').datagrid('getChecked');
          var data=[];
            $.each(rows,function(index,item){
                if(item.STATUS==0){
                    data.push(item);
                }
            });
        if(data.length==0){displayMessage("请选择至少一条【待提交】领料提请单信息，再进行操作",false);return;}
         page.post({action:'deleteTempMaterialRequestData',data:JSON.stringify(data)}, function (res) {
            if (res.Result) {
                page.getTempMaterialRequestData();
            }
            displayMessage(res.Message, res.Result);
        });
    },
    //查询重置
    searchReset: function () {
        $('#searchForm').form('clear');
        page.bind();
    },

    //清除方法，重要！！！
    reset: function (iscondition, isresult) {
        clearMessage();
    },
    //post数据
    post: function ( param, callback) {
        $.ajax({
            type: "Post",
            url: param.url==undefined?page.ajaxUrl:param.url,
            data: param,
            cashe: false,
            async: true,
            dataType: "json",
            beforeSend: function () {
                $.messager.progress({ text: '', msg: '处理中...' });
            },
            success: function (data) {
                $.messager.progress('close');
                callback(data);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.messager.progress('close');
                displayMessage(XMLHttpRequest.responseText, false);
            }
        });
    }
}
$(function () {
    page.init();
});
</script>

<script src="/InSiteWebApplication/Scripts/ZsJs/selectCombox.js" type="text/javascript"></script>